<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>店铺页面</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    html, body {
      width: 100%;
      height: 100%;
      overflow: hidden;
    }
    webview {
      width: 100%;
      height: 100%;
      display: inline-flex;
    }
  </style>
</head>
<body>
  <webview id="detached-webview" style="width: 100%; height: 100%;"></webview>

  <script>
    let ipcRenderer = null
    try {
      ipcRenderer = require('electron').ipcRenderer
    } catch (e) {
      // ipcRenderer 不可用
    }

    const webview = document.getElementById('detached-webview')

    if (!webview) {
      // webview 元素不存在
    }

    // 等待主进程发送标签页信息
    if (ipcRenderer) {
      ipcRenderer.once('detached-tab-info', (event, data) => {
        const { shopId, shopName, partition, url } = data

        // 设置窗口标题
        if (shopName) {
          document.title = shopName
        }

        // 配置 webview
        if (webview) {
          webview.setAttribute('partition', partition)
          webview.setAttribute('allowpopups', 'true')
          webview.setAttribute('nodeintegration', 'false')
          webview.setAttribute('webpreferences', 'nativeWindowOpen=yes')
          
          // 加载 URL（主进程已经设置了 Cookie，这里直接加载 URL 即可）
          if (url && url !== 'about:blank') {
            webview.setAttribute('src', url)
          } else {
            webview.setAttribute('src', 'about:blank')
          }
        }
      })
    }
  </script>
</body>
</html>

